import { App, Component, Plugin } from 'vue'

/**
 * 生成全局注册组件库中所有组件的插件
 *
 * @param {Component} components 组件库中的组件组成的列表
 * @returns {Plugin} 全局注册组件库中所有组件的插件
 */
export const genComponentsLibGlobalRegister = (components: Component[]): Plugin => {
  return (app: App): App => {
    for (const component of components) {
      app.component(component.name as string, component)
    }
    return app
  }
}

export type GenComponentsLibGlobalRegisterType = typeof genComponentsLibGlobalRegister
